import Vue from 'vue'
import Vuex from 'vuex'
import app from './modules/app'
import dict from './modules/dict'
import user from './modules/user'
import tagsView from './modules/tagsView'
import permission from './modules/permission'
import settings from './modules/settings'
import getters from './getters'

const state = {
  theme: "light", //light浅色模式  //dark深色模式
};

const mutations = {
  // 设置切换主题
  setTheme(state, theme) {
    state.theme = theme;
    localStorage.setItem("air-conditioner-theme", theme);
    document.head
      .querySelector("#theme-link")
      .setAttribute("href", `/css/theme-${theme}.css`);
  },
  //获取缓存主题
  getTheme(state) {
    state.theme = localStorage.getItem("air-conditioner-theme") || "light";
    document.head
      .querySelector("#theme-link")
      .setAttribute("href", `/css/theme-${state.theme}.css`);
  }
}




Vue.use(Vuex)

const store = new Vuex.Store({
  state,
  mutations,
  modules: {
    app,
    dict,
    user,
    tagsView,
    permission,
    settings
  },
  getters
})

export default store
